home *** CD-ROM | disk | FTP | other *** search
/ Megahits 3 / Megahits 3 (1994)(GTI - Rhein-Main-Soft)(DE)[!].iso / module / utilities / archives / mod2midi3.lha / Mod2Midi / source / AmigaWIN.C next >
C/C++ Source or Header  |  1993-01-15  |  26KB  |  1,189 lines

  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. #include <exec/types.h>
  6. #include <intuition/intuitionbase.h>
  7. #include <intuition/intuition.h>
  8. #include <intuition/classes.h>
  9. #include <intuition/classusr.h>
  10. #include <intuition/imageclass.h>
  11. #include <intuition/gadgetclass.h>
  12. #include <libraries/gadtools.h>
  13. #include <graphics/gfxbase.h>
  14.  
  15. #include <proto/exec.h>                // use amiga library stuff
  16. #include <proto/dos.h>
  17. #include <proto/graphics.h>
  18. #include <proto/intuition.h>
  19. #include <proto/gadtools.h>
  20. #include <proto/asl.h>
  21. #include <proto/utility.h>
  22. #include <proto/diskfont.h> 
  23. #include <proto/intuition.h>
  24.  
  25. #include <libraries/reqtools.h>
  26. #include <proto/reqtools.h>
  27.  
  28. #include "AmigaWIN.h"
  29. #include "rawkeys.h"
  30. #include "mod2midi_globals.h"
  31.  
  32. #include "mod2midi_rev.h"
  33.  
  34.  
  35. UBYTE version_str[] = { VERSTAG };
  36.  
  37. struct ReqToolsBase *ReqToolsBase;
  38.  
  39. #define    FW    7        // font width
  40. #define    FH    8        // font height
  41.  
  42. #define    Input_CNT    1
  43. #define    GD_f1        1
  44. typedef char *string;
  45.  
  46. struct Screen         *Scr = NULL;
  47. APTR                   VisualInfo = NULL;
  48. struct Window         *InputWnd = NULL;
  49. struct Gadget         *InputGList = NULL;
  50. struct Gadget         *InputGadgets[10];
  51. struct Menu           *InputMenus = NULL;
  52. UWORD                  InputLeft = 50;
  53. UWORD                  InputTop = 91;
  54. UWORD                  InputWidth = 80*FW;
  55. UWORD                  InputHeight = (25*FH)+18;
  56. UBYTE                 InputWdt[100];
  57.  
  58. struct TextAttr thinpaz8 = {
  59.     ( STRPTR )"thinpaz.font", 8, 0x00, 0x00 };
  60.  
  61. struct TextAttr topaz8 = {
  62.     ( STRPTR )"topaz.font", 8, 0x00, 0x00 };
  63.  
  64. struct TextFont    *thinpazfont8;
  65.  
  66. struct NewMenu InputNewMenu[] = {
  67.     NM_TITLE, (STRPTR)"Project", NULL, 0, NULL, NULL,
  68.         NM_ITEM, (STRPTR)"Select midi file", (STRPTR)"d", 0, 0x0L, NULL,
  69.         NM_ITEM, (STRPTR)"Select source mod file", (STRPTR)"s", 0, NULL, NULL,
  70.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  71.         NM_ITEM, (STRPTR)"Convert Now", (STRPTR)"c", 0, NULL, NULL,
  72.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  73.         NM_ITEM, (STRPTR)"About", (STRPTR)"?", 0, NULL, NULL,
  74.         NM_ITEM, (STRPTR)"Quit", (STRPTR)"q", 0, NULL, NULL,
  75.     NM_TITLE, (STRPTR)"Samples", NULL, 0, NULL, NULL,
  76.         NM_ITEM, (STRPTR)"Remap Samples to MID instruments", (STRPTR)"m", 0, 0x0L, NULL,
  77.         NM_ITEM, (STRPTR)"Transposing", (STRPTR)"t", 0, NULL, NULL,
  78.         NM_ITEM, (STRPTR)"Volume Shift", (STRPTR)"v", 0, NULL, NULL,
  79.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  80.         NM_ITEM, (STRPTR)"Save Info", (STRPTR)"i", 0, NULL, NULL,
  81.     NM_TITLE, (STRPTR)"Options", NULL, 0, NULL, NULL,
  82.         NM_ITEM, (STRPTR)"Drum Channel", (STRPTR)"h", 0, 0x0L, NULL,
  83.         NM_ITEM, (STRPTR)"Tempo Type", NULL, 0, NULL, NULL,
  84. };
  85.  
  86. UWORD InputGTypes[] = {
  87.     BUTTON_KIND,
  88. };
  89.  
  90. struct NewGadget InputNGad[] = {
  91.     6, 3, 45, 12, (UBYTE *)"Quit", NULL, GD_f1, PLACETEXT_IN, NULL, NULL,
  92. };
  93.  
  94. ULONG InputGTags[] = {
  95.     (GT_Underscore), '_', (TAG_DONE),
  96. };
  97.  
  98.  
  99.  
  100.  
  101. /*
  102.  * --- Message info
  103.  */
  104. ULONG            IClass;
  105. UWORD            Qualifier, Code;
  106.  
  107. struct            Gadget    *IObject;
  108. ULONG            version;
  109.  
  110.  
  111. struct    FileRequester    *filereq;
  112.  
  113.  
  114. /*
  115.  * --- Close the libraries which are opened by me.
  116.  */
  117. void CloseLibraries( void ){
  118.     if( AslBase ){
  119.         if ( filereq )
  120.             FreeAslRequest( filereq );
  121.     }
  122.  
  123.     if (DiskFontBase)        CloseLibrary( (struct Library *) DiskFontBase );
  124.     if (GadToolsBase)        CloseLibrary(( struct Library * )GadToolsBase );
  125.     if (IntuitionBase)        CloseLibrary(( struct Library * )IntuitionBase );
  126.     if (DosBase)            CloseLibrary(( struct Library * )DosBase );
  127.     if (GfxBase)            CloseLibrary(( struct Library * )GfxBase );
  128.     if (AslBase)            CloseLibrary(( struct Library * )AslBase );
  129.     if (ReqToolsBase)        CloseLibrary(( struct Library * )ReqToolsBase );
  130. }
  131.  
  132.  
  133. /*
  134.  * --- Open lots of libraries that I need.
  135.  */
  136. long OpenLibraries( void ){
  137.     struct    TagItem    AslTags[] = { 0,0 };
  138.  
  139.  
  140.     if ( !(GfxBase = (struct GfxBase *) OpenLibrary((UBYTE *) "graphics.library" , 33l ))) {
  141.         printf("\tgraphics.library\n");
  142.         return FALSE;
  143.     }
  144.  
  145.     if ( !(DosBase = (struct DosBase *) OpenLibrary((UBYTE *) "dos.library", 33l ))) {
  146.         printf("\tdos.library\n");
  147.         return FALSE;
  148.     }
  149.  
  150.     if ( !(IntuitionBase = (struct IntuitionBase *) OpenLibrary((UBYTE *) "intuition.library", 33l ))) {
  151.         printf("\tintuition.library\n");
  152.         return FALSE;
  153.     }
  154.  
  155.     if ( !(GadToolsBase = (struct Library *) OpenLibrary((UBYTE *) "gadtools.library", 36l ))) {
  156.         printf("\tCan't open gadtools.library 36+, trying gadtoolsl13.library\n");
  157.         if ( !(GadToolsBase = (struct Library *) OpenLibrary((UBYTE *) "gadtools13.library", 34l ))) {
  158.             printf("\tgadtools13.library\n");
  159.             return FALSE;
  160.         }
  161.     }
  162.  
  163.     if ( !(AslBase = (struct Library *) OpenLibrary((UBYTE *) "asl.library", 36l ))) {
  164.         printf("\tCan't open asl.library 36+, trying reqtools.library\n");
  165.     }
  166.     else {
  167.         filereq = (struct FileRequester *) AllocAslRequest( ASL_FileRequest,AslTags );
  168.         if( !filereq ) {
  169.             printf("\tcant allocate asl requester");
  170.             return FALSE;
  171.         }
  172.     }
  173.  
  174.     if ( !(ReqToolsBase = (struct ReqToolsBase *) OpenLibrary((UBYTE *) "reqtools.library", 38l ))) {
  175.         printf("\tCan't open reqtools.library 38+\n");
  176.         if( !AslBase ) {
  177.             printf("\tNo asl.library or reqtools.library present?  Cya.\n");
  178.             return FALSE;
  179.         }
  180.         else
  181.             printf("\tWe can live without reqtools.library.\n");
  182.     }
  183.  
  184.  
  185.     if ( !(DiskFontBase = (struct Library *) OpenLibrary((UBYTE *) "diskfont.library", 33l ))) {
  186.         printf("\tdiskfont.library\n");
  187.         return FALSE;
  188.     }
  189.  
  190.     return TRUE;
  191. }
  192.  
  193.  
  194. /*
  195.  * --- Clears all message from a message port.
  196.  */
  197. void ClearMsgPort( struct MsgPort *mport )
  198. {
  199.     struct IntuiMessage  *msg;
  200.  
  201.     while ( msg = GT_GetIMsg( mport )) GT_ReplyIMsg( msg );
  202. }
  203.  
  204.  
  205.  
  206.  
  207. /*
  208.  * --- Reads a message from the window message port.
  209.  * --- Returns TRUE if a message was read and puts the
  210.  * --- message data in the globals. Return FALSE if there
  211.  * --- was no message at the port.
  212.  */
  213. long ReadIMsg( struct Window *iwnd )
  214. {
  215.     struct IntuiMessage *imsg;
  216.  
  217.     if ( imsg = GT_GetIMsg( iwnd->UserPort )) {
  218.  
  219.         IClass      =   imsg->Class;
  220.         Qualifier   =   imsg->Qualifier;
  221.         Code        =   imsg->Code;
  222.         IObject     =   imsg->IAddress;
  223.  
  224.         GT_ReplyIMsg( imsg );
  225.  
  226.         return TRUE;
  227.     }
  228.     return FALSE;
  229. }
  230.  
  231.  
  232.  
  233.  
  234. /**********************************************************************
  235.  *
  236.  *                        Draw3DOutBox
  237.  *    Description : just like normal bevelbox except inside color is selectable
  238.  *                  plus it looks MONUMENTAL!
  239.  *                                ¯¯¯¯¯¯¯¯¯¯¯
  240.  *  Returns        : NULL
  241.  *    Globals        : usual
  242.  *
  243.  */
  244. void Draw3DBox(
  245.     struct    RastPort *rp,        // window rastport to draw into
  246.     UWORD    xpos,                // X coordinate to place MEGA-BEVEL
  247.     UWORD    ypos,                // Y coordinate to place MEGA-BEVEL
  248.     UWORD    xsize,                // X size of MEGA-BEVEL
  249.     UWORD    ysize,                // X size of MEGA-BEVEL
  250.     UWORD    shine_pen,            // top-left pen
  251.     UWORD    body_pen,            // central pen
  252.     UWORD    shadow_pen            // bot-right pen
  253. ){
  254.  
  255. #define    LineDraw(x,y,x2,y2)    Move( rp, x , y); \
  256.                             Draw( rp, x2, y2 )
  257.  
  258.     xsize--;ysize--;
  259.  
  260.     SetAPen( rp, body_pen );
  261.     RectFill( rp, xpos, ypos, xpos+xsize, ypos+ysize);
  262.  
  263.     LineDraw( xpos, ypos, xpos+1, ypos+1 );
  264.     LineDraw( xpos+xsize-1, ypos+ysize-1, xpos+xsize, ypos+ysize );
  265.  
  266.     SetAPen( rp, shine_pen );
  267.     LineDraw( xpos+0, ypos+0, xpos+xsize-1, ypos );
  268.     LineDraw( xpos+0, ypos+1, xpos+xsize-2, ypos+1 );
  269.     LineDraw( xpos+0, ypos+0, xpos, ypos+ysize-1 );
  270.     LineDraw( xpos+1, ypos+0, xpos+1, ypos+ysize-2 );
  271.  
  272.     SetAPen( rp, shadow_pen );
  273.     LineDraw( xpos+1, ypos+ysize-0, xpos+xsize-1, ypos+ysize-0 );
  274.     LineDraw( xpos+2, ypos+ysize-1, xpos+xsize-2, ypos+ysize-1 );
  275.     LineDraw( xpos+xsize-0, ypos+1, xpos+xsize-0, ypos+ysize-1 );
  276.     LineDraw( xpos+xsize-1, ypos+2, xpos+xsize-1, ypos+ysize-2 );
  277.  
  278.     SetAPen( rp, 2 );
  279.     if ( shine_pen > shadow_pen ){
  280.         LineDraw( xpos+0, ypos+0, xpos+2, ypos+0 );
  281.         LineDraw( xpos+0, ypos+0, xpos+0, ypos+2 );
  282.     }
  283.     else {
  284.         LineDraw( xpos+xsize, ypos+ysize, xpos+xsize-2, ypos+ysize );
  285.         LineDraw( xpos+xsize, ypos+ysize, xpos+xsize-0, ypos+ysize-2 );
  286.     }
  287. }
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295. int OpenInputWindow( void )
  296. {
  297.     struct NewGadget    ng;
  298.     struct Gadget    *g;
  299.     UWORD        lc, tc;
  300.     UWORD        offx, offy;
  301.  
  302.     if( !OpenLibraries() ) {
  303.         printf("libraries could not be opened!!!\n");
  304.         return 1L;
  305.     }
  306.  
  307.     version=GfxBase->LibNode.lib_Version;
  308.  
  309.     Scr = IntuitionBase->ActiveScreen;
  310.     if ( ! (thinpazfont8  = OpenDiskFont( &thinpaz8 )) ) {
  311.         printf("cant open thinpaz.font 8, trying topaz 8\n");
  312.         if ( ! (thinpazfont8  = OpenDiskFont( &topaz8 )) ) {
  313.             printf("cant open any fonts??\n");
  314.         }
  315.     }
  316.  
  317.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  318.         return( 1L );
  319.  
  320.     offx = Scr->WBorLeft; offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  321.  
  322.     if ( ! ( g = CreateContext( &InputGList )))
  323.         return( 1L );
  324.  
  325.     for( lc = 0, tc = 0; lc < Input_CNT; lc++ ) {
  326.  
  327.         CopyMem((char * )&InputNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  328.  
  329.         ng.ng_VisualInfo = VisualInfo;
  330.         ng.ng_TextAttr   = &thinpaz8;
  331.         ng.ng_LeftEdge  += offx;
  332.         ng.ng_TopEdge   += offy;
  333.  
  334.         InputGadgets[ lc ] = g = CreateGadgetA((ULONG)InputGTypes[ lc ], g, &ng, ( struct TagItem * )&InputGTags[ tc ] );
  335.  
  336.         while( InputGTags[ tc ] ) tc += 2;
  337.         tc++;
  338.  
  339.         if ( NOT g )
  340.             return( 2L );
  341.     }
  342.  
  343.  
  344.     if ( ! ( InputMenus = CreateMenus( InputNewMenu,
  345.                     GTMN_FrontPen,        2L,
  346.                     TAG_DONE )))
  347.         return( 3L );
  348.  
  349.     LayoutMenus( InputMenus, VisualInfo,
  350.             //        GTMN_TextAttr,         &helvetica18,
  351.                     GTMN_NewLookMenus,    TRUE,
  352.                     TAG_DONE );
  353.  
  354.     if( version >= 36 ){
  355.         if ( ! ( InputWnd = OpenWindowTags( NULL,
  356.                 WA_Left,        InputLeft,
  357.                 WA_Top,            InputTop,
  358.                 WA_Width,        InputWidth,
  359.                 WA_Height,        InputHeight + offy,
  360.                 WA_IDCMP,        IDCMP_MOUSEBUTTONS|BUTTONIDCMP|INTEGERIDCMP|
  361.                                 IDCMP_CHANGEWINDOW|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|
  362.                                 IDCMP_ACTIVEWINDOW|IDCMP_MENUPICK|IDCMP_VANILLAKEY|IDCMP_RAWKEY,
  363.                 WA_Flags,        WFLG_NEWLOOKMENUS|WFLG_ACTIVATE|WFLG_DRAGBAR|WFLG_DEPTHGADGET|
  364.                                 WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_GIMMEZEROZERO,
  365.             //    WA_Gadgets,        InputGList,
  366.                 WA_Title,        InputWdt,
  367.                 WA_PubScreen,    NULL,
  368.                 WA_MinWidth,    InputWidth,
  369.                 WA_MinHeight,    InputHeight + offy,
  370.                 WA_MaxWidth,    InputWidth + 140,
  371.                 WA_MaxHeight,    InputHeight + offy + 500,
  372.                 TAG_DONE ))) {
  373.         printf("Could not open window using ... OpenWindowTags()\n");
  374.         return( 4L );
  375.         }
  376.     }
  377.     else {
  378.         struct NewWindow mywin    = {
  379.             10, 14, 80*FW, (25*FH)+18 + 11,
  380.             0,1,
  381.             IDCMP_MOUSEBUTTONS|BUTTONIDCMP|INTEGERIDCMP|
  382.                 IDCMP_CHANGEWINDOW|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|
  383.                 IDCMP_ACTIVEWINDOW|IDCMP_MENUPICK|IDCMP_VANILLAKEY|IDCMP_RAWKEY,
  384.             WFLG_NEWLOOKMENUS|WFLG_ACTIVATE|WFLG_DRAGBAR|WFLG_DEPTHGADGET|
  385.                 WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_GIMMEZEROZERO,
  386.             NULL, NULL,
  387.             InputWdt,
  388.             NULL, NULL,
  389.             80*FW,
  390.             (25*FH)+18 + 11,
  391.             80*FW + 140,
  392.             (25*FH)+18 + 11 + 500,
  393.             WBENCHSCREEN
  394.         };
  395.  
  396.         if( !(InputWnd = OpenWindow( &mywin )) ) {
  397.             printf("Could not open window using ... OpenWindow()\n");
  398.             return( 4L );
  399.         }
  400.     }
  401.  
  402.     if( thinpazfont8 )
  403.         SetFont( InputWnd->RPort, thinpazfont8 );
  404.  
  405.     SetMenuStrip( InputWnd, InputMenus );
  406.  
  407.     GT_RefreshWindow( InputWnd, NULL );
  408.  
  409.     return( 0L );
  410. }
  411.  
  412. void CloseInputWindow( void )
  413. {
  414.     InputLeft = InputWnd->LeftEdge;
  415.     InputTop = InputWnd->TopEdge;
  416.  
  417.     if ( InputMenus      ) {
  418.         ClearMenuStrip( InputWnd );
  419.         FreeMenus( InputMenus );
  420.         InputMenus = NULL;    }
  421.  
  422.     if ( InputWnd ) {
  423.         CloseWindow( InputWnd );
  424.         InputWnd = NULL;
  425.     }
  426.  
  427.     if ( InputGList ) {
  428.         FreeGadgets( InputGList );
  429.         InputGList = NULL;
  430.     }
  431. }
  432.  
  433.  
  434.  
  435.  
  436.  
  437. /**********************************************************************
  438.  *
  439.  *                        InputMenus()
  440.  *    Description : Handles all menu events
  441.  *  Returns        : BOOL
  442.  *    Globals        :
  443.  *
  444.  */
  445. LONG HandleInputMenus( void ){
  446.     struct    MenuItem        *Next;
  447.     LONG    ret=-1;
  448.     UWORD    menu, item, sub;
  449.  
  450.     while( Code != MENUNULL ) {
  451.         Next = ItemAddress(  InputMenus, Code );
  452.         menu = MENUNUM( Code );
  453.         item = ITEMNUM( Code );
  454.         sub  = SUBNUM( Code );
  455.         switch ( menu ) {
  456.             case    0:
  457.                 switch ( item ) {
  458.                     case    0:    ret = 0; break;
  459.                     case    1:    ret = 1; break;
  460.                     case    3:    ret = 2; break;
  461.                     case    5:    ret = 5; break;
  462.                     case    6:    ret = 99; break;
  463.                 }
  464.                 break;
  465.             case    1:
  466.                 switch ( item ) {
  467.                     case    0:    ret = 3; break;        // remap
  468.                     case    1:    ret = 6; break;        // transpose
  469.                     case    2:    ret = 9; break;        // volume
  470.                     case    4:    ret = 4; break;        // save info
  471.                 }
  472.                 break;
  473.             case    2:
  474.                 switch ( item ) {
  475.                     case    0:    ret = 7; break;        // drum ch
  476.                     case    1:    ret = 8; break;        // tempo
  477.                     case    2:    ret = 8; break;        //  "
  478.                 }
  479.                 break;
  480.         }
  481.         Code = Next->NextSelect;
  482.     }
  483.     return ret;
  484. }
  485.  
  486.  
  487.     WORD    rawkey=0;
  488.     WORD    normkey=0;
  489.  
  490. int GetIntuiEvent( void ){
  491.     int ret=-1;
  492.  
  493. //printf("waitport\n");
  494.     WaitPort( InputWnd->UserPort );
  495. //    while ( ReadIMsg( InputWnd )) {
  496.         ReadIMsg( InputWnd ); {
  497. //printf("decode msg\n");
  498.         ret=-1;
  499.         rawkey=NULL; normkey = NULL;
  500.         switch ( IClass ) {
  501.             case    IDCMP_CLOSEWINDOW:            // Key short cuts
  502.                 ret = 99;
  503.                 break;
  504.  
  505.             case    IDCMP_MOUSEBUTTONS:
  506.                 switch ( Code ){
  507.                     case SELECTUP:
  508.                         break;
  509.                     case SELECTDOWN:
  510.                         break;
  511.                 }
  512.                 break;
  513.  
  514.             case    IDCMP_GADGETUP:
  515.                 switch ( IObject->GadgetID ) {
  516.                     case    GD_f1:
  517.                         ret = 99;
  518.                         break;
  519.                 }
  520.                 break;
  521.  
  522.             case    IDCMP_VANILLAKEY:            // Key short cuts
  523.                 normkey = Code;
  524.                 if( version <= 34 )
  525.                 switch( Code ){
  526.                     case '8' : rawkey = KEY_UP; break;
  527.                     case '2' : rawkey = KEY_DOWN; break;
  528.                 }
  529.                 break;
  530.  
  531.             case    IDCMP_RAWKEY:
  532.                 switch( Code ){
  533.                     case KEY_P8        : rawkey = KEY_UP;break;
  534.                     case KEY_P2        : rawkey = KEY_DOWN;break;
  535.                     case KEY_P4        : rawkey = KEY_LEFT;break;
  536.                     case KEY_P6        : rawkey = KEY_RIGHT;break;
  537.  
  538.                     case KEY_UP        :
  539.                     case KEY_DOWN    :
  540.                     case KEY_LEFT    :
  541.                     case KEY_RIGHT    : rawkey = Code;    break;
  542.                     default            : rawkey = NULL;    break;
  543.                 }
  544.                 break;
  545.  
  546.             case    IDCMP_MENUPICK:
  547.                 ret = HandleInputMenus();
  548.                 break;
  549.  
  550.             case    IDCMP_CHANGEWINDOW:
  551.                 break;
  552.  
  553.             case    IDCMP_ACTIVEWINDOW:
  554.                 ClearMsgPort( InputWnd->UserPort );
  555.                 break;
  556.  
  557.             case    IDCMP_REFRESHWINDOW:
  558.                 GT_BeginRefresh( InputWnd );
  559.                 GT_EndRefresh( InputWnd, TRUE);
  560.                 break;
  561.         }
  562.     }
  563. //printf("ret=%d   normkey=%d  rawkey=%d\n",ret,normkey,rawkey);
  564.     return ret;
  565. }
  566.  
  567.  
  568.  
  569.  
  570. /**********************************************************************
  571.  *
  572.  *                        AslFileRequest
  573.  *
  574.  *    Description : Put up the ASL FileRequester
  575.  *    Returns        : UBYTE pointer to filename ascii (NULL terminated)
  576.  *    Globals        :
  577.  *
  578.  */
  579. UBYTE *AslFileRequest(
  580.     UBYTE type,                // 'l'=load / 's'=save
  581.     UBYTE *title,            // title of requester window
  582.     UBYTE *drawer,            // the drawer to open into
  583.     UBYTE *pattern            // the pattern to use
  584. ){
  585. static
  586.     UBYTE    FileName[180];
  587.     UBYTE    *char1, *ret;
  588.     UWORD    flag1, flag2, len, x, y;
  589.  
  590.     ret = 0;
  591.  
  592.     if( !filereq ) return ret;
  593.  
  594.     x = 10;                // get current mouse coords
  595.     y = 10;
  596.  
  597.     switch( type ) {
  598.         case    's':
  599.             char1 = "Save";
  600.             flag1 = FILF_SAVE | FILF_PATGAD;
  601.             flag2 = TRUE;
  602.             break;
  603.         case    'l':
  604.             char1 = "Open";
  605.             flag1 = FILF_PATGAD;
  606.             flag2 = FALSE;
  607.             break;
  608.         }
  609.  
  610.     if ( AslRequestTags( filereq,
  611.                         ASL_OKText,             char1,
  612.                         ASL_Hail,                 flag1,
  613.                         ASLFR_Flags2,            NULL,
  614.                         ASLFR_DoSaveMode,        flag2,
  615.                         ASLFR_DoPatterns,        TRUE,
  616.                         ASLFR_InitialPattern,    pattern,
  617.                         ASLFR_InitialFile,        "HardCore.mod",
  618.                         ASLFR_TitleText,         title,
  619.                         ASLFR_InitialLeftEdge,    x,
  620.                         ASLFR_InitialTopEdge,    y,
  621.                         ASLFR_InitialWidth,        300,
  622.                         ASLFR_InitialHeight,    284,
  623.                         ASLFR_InitialDrawer,    drawer,
  624.                     //    ASLFR_TextAttr,            &helvetica13,
  625.                         TAG_DONE ) ) {
  626.         strcpy( FileName, filereq->rf_Dir );
  627.         len = strlen( FileName );
  628.         if ( len-- )
  629.             if ( FileName[ len ] != '/' && FileName[ len ] != ':' )
  630.                 strcat( FileName, "/" );
  631.         strcat( FileName, filereq->rf_File );
  632.         ret = FileName;
  633.     }
  634.  
  635.     return( ret );
  636. }
  637.  
  638.  
  639.  
  640.  
  641.  
  642. /**********************************************************************
  643.  *
  644.  *                        ReqFileRequest
  645.  *
  646.  *    Description : Put up the ASL FileRequester
  647.  *    Returns        : UBYTE pointer to filename ascii (NULL terminated)
  648.  *    Globals        :
  649.  *
  650.  */
  651. UBYTE *ReqFileRequest(
  652.     UBYTE type,                // 'l'=load / 's'=save
  653.     UBYTE *title,            // title of requester window
  654.     UBYTE *drawer,            // the drawer to open into
  655.     UBYTE *pattern            // the pattern to use
  656. ){
  657. static
  658.     UBYTE    FileName[180];
  659.     char    filename[34]={"HardCore.mod"};
  660.  
  661.     UBYTE    *char1, *ret;
  662.     UWORD    flag1, flag2, len, x, y;
  663.     struct rtFileRequester *rt_filereq;
  664. struct TagItem    rt_tags[5];
  665. //            ={
  666. //            RTFI_Flags,        0,
  667. //            RTFI_OkText,    0,
  668. //            RTFI_Height,    0,
  669. //            TAG_DONE, TAG_DONE };
  670.  
  671.  
  672.  
  673.     ret = 0;
  674.  
  675.     if( !(rt_filereq = rtAllocRequestA( RT_FILEREQ, NULL )) )
  676.         return ret;
  677.  
  678.     x = 10;                // get current mouse coords
  679.     y = 10;
  680.  
  681.     switch( type ) {
  682.         case    's':
  683.             char1 = "Save";
  684.             flag1 = FREQF_SAVE | FILF_PATGAD;
  685.             flag2 = TRUE;
  686.             break;
  687.         case    'l':
  688.             char1 = "Open";
  689.             flag1 = FREQF_PATGAD;
  690.             flag2 = FALSE;
  691.             break;
  692.         }
  693.  
  694.     rt_tags[0].ti_Tag = RTFI_Flags;        rt_tags[0].ti_Data = flag1;
  695.     rt_tags[1].ti_Tag = RTFI_OkText;    rt_tags[1].ti_Data = (ULONG)char1;
  696.     rt_tags[2].ti_Tag = RTFI_Height;    rt_tags[2].ti_Data = 284;
  697.  
  698.     if( rtFileRequestA( rt_filereq, filename, title, rt_tags ) ) {
  699.         strcpy( FileName, rt_filereq->Dir );
  700.         len = strlen( FileName );
  701.         if ( len-- )
  702.             if ( FileName[ len ] != '/' && FileName[ len ] != ':' )
  703.                 strcat( FileName, "/" );
  704.         strcat( FileName, filename );
  705.         ret = FileName;
  706.     }
  707.  
  708.     if( rt_filereq )
  709.         rtFreeRequest( rt_filereq );
  710.  
  711.     return( ret );
  712. }
  713.  
  714.  
  715.  
  716. //--------------------------------------------------------------------------
  717.  
  718. UBYTE    str[100];
  719.  
  720. void cprintf( UBYTE *a, int b, UBYTE *c ){
  721.     int len=strlen(c);
  722.  
  723.     if( c ) {
  724.         if( *(c+len-1) == 13 )
  725.             *(c+len-1)=NULL;
  726.     }
  727.     sprintf(str,a,b,c);
  728.     Text( InputWnd->RPort, str, strlen(str) );
  729. }
  730.  
  731. void cputs( UBYTE *a ){
  732.     Text( InputWnd->RPort, a, strlen(a) );
  733. }
  734.  
  735. void cputchar( UBYTE *a, UBYTE c ){
  736.     sprintf(str,a,c);
  737.     Text( InputWnd->RPort, str, strlen(str) );
  738. }
  739.  
  740.  
  741. //--------------------------------------------------------------------------
  742.  
  743.  
  744. void EndWindows( void ){
  745.     if ( thinpazfont8 )
  746.         CloseFont( thinpazfont8 );
  747.     CloseInputWindow();
  748.     CloseLibraries();
  749. }
  750.  
  751.  
  752.  
  753. void MainWindow(string title, int num, ...)
  754. /* Post: Screen is set up with a nice title and num menus */
  755. {
  756.     va_list args;
  757.  
  758.     strcpy( InputWdt, title );
  759.  
  760.     if( OpenInputWindow() ) {
  761.         EndWindows();
  762.         printf("Failure occured!\n");
  763.         exit(5);
  764.     }
  765. }
  766.  
  767.  
  768.  
  769.     WORD    curr_x=1,curr_y=1,
  770.             left_x=1,top_y=1,
  771.             right_x=80,bottom_y=25,
  772.             pos_x=1,pos_y=1;
  773.  
  774. void gotoxy( WORD x, WORD y ){
  775.     pos_x = x; pos_y=y;
  776.     curr_x=(x+left_x)*FW;    curr_y=(y+top_y)*FH;
  777.     Move( InputWnd->RPort, curr_x, curr_y );
  778. }
  779. void textcolor( WORD n ){
  780.     SetAPen( InputWnd->RPort, n );
  781. }
  782. void textbackground( WORD n ){
  783.     SetBPen( InputWnd->RPort, n );
  784. }
  785.  
  786. void window( int x, int y, int x2, int y2 ){
  787.     left_x  =x;        top_y   =y;
  788.     right_x =x2;    bottom_y=y2;
  789. //printf("window:x=%d y=%d x2=%d y2=%d\n",x, y, x2, y2);
  790. }    
  791.  
  792. void renderwindow( int x, int y, int x2, int y2 ){
  793.     Draw3DBox( InputWnd->RPort, (x*FW)-12, (y*FH)-6, (x2*FW)+12, (y2*FH)+16, 2,3,1 );
  794. //printf("rwindow:x=%d y=%d x2=%d y2=%d\n",x, y, x2, y2);
  795. }
  796.  
  797.  
  798. void PrintBar(string s, int w, int y)
  799. /* Post: String s (width w) is highlighted in the text window on line y */
  800. {
  801.     gotoxy(1, y+1);
  802.     textcolor(1);
  803.     textbackground(2);
  804.     cprintf(" %-*s ", w, s);
  805. }
  806.  
  807. void ClearBar(string s, int w, int y)
  808. /* Post: String s (width w) is normalized in the text window on line y */
  809. {
  810.     gotoxy(1, y+1);
  811.     textcolor(2);
  812.     textbackground(3);
  813.     cprintf(" %-*s ", w, s);
  814. }
  815.  
  816. void Beep( void ){
  817.     DisplayBeep( NULL );
  818. }
  819.  
  820. int Choice( void ){
  821.     int ret=-1;
  822.  
  823.     ret = GetIntuiEvent();
  824.  
  825.     return ret;
  826. }
  827.  
  828.  
  829. void ScrollWindowUp( void ){
  830.     ClipBlit( InputWnd->RPort, left_x*FW, ((top_y+1)*FH)+2,
  831.               InputWnd->RPort, left_x*FW, ((top_y)*FH)+2,
  832.              (right_x-left_x)*FW,
  833.              ((bottom_y-top_y-1)*FH)+2, 0xc0 );
  834. }
  835.  
  836. void ScrollWindowDown( void ){
  837.     ClipBlit( InputWnd->RPort, left_x*FW, (top_y*FH)+2,
  838.               InputWnd->RPort, left_x*FW, ((top_y+1)*FH)+2,
  839.              (right_x-left_x)*FW,
  840.              ((bottom_y-top_y-1)*FH), 0xc0 );
  841. }
  842.  
  843.  
  844.  
  845.  
  846. void insline( void ){
  847.     ;
  848. }
  849.  
  850. void clreol( int x ){
  851.     int lp;
  852.  
  853.     cprintf(" %-*s ", right_x-(x+left_x), " ");
  854. }
  855.  
  856.  
  857. #define getch GetCursorKeys
  858. WORD GetCursorKeys( void ){
  859.     GetIntuiEvent();
  860.     if( rawkey ) {
  861.         if( rawkey == KEY_UP ) return -72;
  862.         if( rawkey == KEY_DOWN ) return -80;
  863.         if( rawkey == KEY_LEFT ) return -75;
  864.         if( rawkey == KEY_RIGHT ) return -77;
  865.     }
  866.     else
  867.         return normkey;
  868. }
  869.  
  870.  
  871. void ClearWin( void ){
  872.     textcolor(0);
  873.     RectFill( InputWnd->RPort, 0, 0, 80*FW,(26*FH)+1);
  874.     window(1, 1, 80, 25);
  875. }
  876.  
  877.  
  878. int ScrollChoice( char *title, char **sp, int w)
  879. /*
  880.  * Returns: The offset of the string from s which is chosen, -1 on none
  881.  *    s points to the start of a list of strings, max length w, NULL term.
  882.  */
  883. {
  884.     string s, t, *srt, *end;
  885.     int l, p, cur, ch, x = -1;
  886.  
  887.     if (strlen(title) > w)
  888.         w = strlen(title);
  889.  
  890.     ClearWin();
  891.     textcolor(1);
  892.     textbackground(0);
  893.     gotoxy(1, 25);
  894.     cputs("Use cursor keys and <RETURN> to make a selection (ESC=back one level).");
  895.  
  896.     for (end = sp, l = 0; *end!=NULL && l<20; l++);
  897.  
  898.     renderwindow(6, 1, w, l+1);
  899.  
  900.     textcolor(2);
  901.     textbackground(3);
  902.     gotoxy(3 + (w - strlen(title))/2, 1);
  903.     cprintf("-- %-*s --", 14, title );
  904.  
  905.     srt = end = sp;
  906.     for (end = sp, l = 0; *end!=NULL && l<20; l++) {
  907.         gotoxy(6, l+2);
  908.         cprintf(" %-*s", w, *(end++) );
  909.     }
  910.     end--;
  911.  
  912.     window(6, 2, 8+w, l+2);
  913.  
  914.     PrintBar(*srt, w, p = 0);
  915.     cur = 0;
  916.     x = -1;
  917.     do {
  918.         ch = GetCursorKeys();
  919.         if(ch<0) {
  920.             if (ch==-72)
  921.                 if (!cur)
  922.                     Beep();
  923.                 else if (p) {
  924.                     ClearBar(*(srt+p), w, p);
  925.                     p--;
  926.                     PrintBar(*(srt+p), w, p);
  927.                     cur--;
  928.                 } else {
  929.                     ClearBar(*(srt--), w, 0);
  930.                     gotoxy(1, 1);
  931.                     ScrollWindowDown();
  932.                     gotoxy(w+3, 1);
  933.                     PrintBar(*srt, w, 0);
  934.                     end--;
  935.                     cur--;
  936.                 }
  937.             else if (ch==-80)
  938.                 if (p==l-1 && *(end+1)==NULL)
  939.                     Beep();
  940.                 else if (p < l-1) {
  941.                     ClearBar(*(srt+p), w, p);
  942.                     p++;
  943.                     cur++;
  944.                     PrintBar(*(srt+p), w, p);
  945.                 } else {
  946.                     ClearBar(*end, w, p);
  947.                     end++;
  948.                     ScrollWindowUp();
  949.                     gotoxy(w+3, l);
  950.                     cur++;
  951.                     PrintBar(*end, w, p);
  952.                     srt++;
  953.                 }
  954.         } else
  955.         if (ch==13)
  956.             x = cur;
  957.     } while (x < 0 && ch != 27);
  958.     ClearWin();
  959.     textcolor(1);
  960.     textbackground(0);
  961.     gotoxy(1, 25);
  962.     cputs("Select an option from the menu.");
  963.     return x;
  964. }
  965.  
  966.  
  967.  
  968. /* returns the ysize of the box drawn */
  969. int PrintBox(string *sp, int *x1, int *y1, int *w1) {
  970.     int w, x, i, j, ys=0;
  971.     string s, t, *c;
  972.  
  973.     if (*sp==NULL)
  974.         return;
  975.     c = sp;
  976.     for (w = strlen(*(c++)), i = 1; *c!=NULL; c++, i++)
  977.         if (w < (x = strlen(*c)))
  978.             w = x;
  979.     *w1 = w + 2;
  980.     *x1 = 1 + (x = (76 - w)/2);
  981.     i = 1 + (21 - i)/2;
  982.     *y1 = i-1;
  983.  
  984.     for (c = sp; *c!=NULL; c++) ys++;
  985.  
  986.     window( *x1, *y1, *w1, ys );
  987.     renderwindow( *x1, *y1, *w1, ys );
  988.  
  989.     textcolor(2);
  990.     textbackground(3);
  991.  
  992.     x=1;i=1;
  993.     for (c = sp; *c!=NULL; c++) {
  994.         gotoxy(x, i++);
  995.         w = strlen(*c);
  996.         cprintf(" %-*s ", w, *c);
  997.     }
  998.     return ys;
  999. }
  1000.  
  1001.  
  1002. void DrawBox( char **sp)
  1003. /* Post: The NULL-terminated array of strings pointed to by sp is printed */
  1004. {
  1005.     int i,i2,i3;
  1006.     PrintBox(sp, &i, &i2, &i3);
  1007. }
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013. // Requesters //////////////////////////////////////////
  1014.  
  1015.  
  1016.  
  1017. char InfoBoxOld( char **sp)
  1018. /*
  1019.  * Returns: The key pressed after the NULL-terminated array of strings
  1020.  *    pointed to by sp is printed.
  1021.  */
  1022. {
  1023.     int k;
  1024.  
  1025.     ClearWin();
  1026.     DrawBox(sp);
  1027.     window(1, 1, 80, 25);
  1028.     textcolor(1);
  1029.     textbackground(0);
  1030.     gotoxy(1, 25);
  1031.     Text( InputWnd->RPort, "Please press a key.", 18 );
  1032.     k = GetCursorKeys();
  1033.     ClearWin();
  1034.     gotoxy(1, 25);
  1035.     Text( InputWnd->RPort, "OK.                ", 18 );
  1036.     return (char)k;
  1037. }
  1038.  
  1039.  
  1040. char InfoBox( char **sp)
  1041. {
  1042.     if( ReqToolsBase ){
  1043.         UBYTE *txt,*txt_ptr;
  1044.         char **sp2;
  1045.  
  1046.         txt = malloc( 4000 );
  1047.         if( txt ){
  1048.             sp2 = sp;
  1049.             txt_ptr=txt;
  1050.             while( *sp2 ) {
  1051.                 txt_ptr+=sprintf(txt_ptr,"%s\n",*sp2 );
  1052.                 sp2++;
  1053.             }
  1054.             rtEZRequestA(txt, "OK", NULL, NULL, NULL);
  1055.             free( txt );    
  1056.             return NULL;
  1057.         }
  1058.         else
  1059.             return InfoBoxOld( sp );
  1060.     }
  1061.     else
  1062.         return InfoBoxOld( sp );
  1063. }
  1064.  
  1065.  
  1066. string FileSelect( char **sp, string def)
  1067. /* Pre: def != NULL */
  1068. /*
  1069.  * Returns: The string entered (or def if none entered), after printing
  1070.  *    box filled with NULL-terminated strings sp.
  1071.  */
  1072. {
  1073.     string s;
  1074.  
  1075.     if( AslBase )
  1076.         s = AslFileRequest( 'l', *sp, "" , "#?" );
  1077.     else
  1078.     if( ReqToolsBase )
  1079.         s = ReqFileRequest( 'l', *sp, "" , "#?" );
  1080.  
  1081.     return s;
  1082. }
  1083.  
  1084.  
  1085.  
  1086. string DialogBox( char **sp, string def)
  1087. /* Pre: def != NULL */
  1088. /*
  1089.  * Returns: The string entered (or def if none entered), after printing
  1090.  *    box filled with NULL-terminated strings sp.
  1091.  */
  1092. {
  1093.     int x, y, w, ch, i=0, ys;
  1094.     string s;
  1095. static    UBYTE buffer[64];
  1096.  
  1097.     if( ReqToolsBase ){
  1098.         UBYTE *txt,*txt_ptr;
  1099.         char **sp2;
  1100.  
  1101.         txt = malloc( 4000 );
  1102.         if( txt ){
  1103.             struct TagItem gtag[3];
  1104.  
  1105.             gtag[0].ti_Tag = RTGS_TextFmt;
  1106.             gtag[0].ti_Data = (ULONG)txt;
  1107.             gtag[1].ti_Tag = TAG_DONE;
  1108.             gtag[1].ti_Data = NULL;
  1109.  
  1110.             sp2 = sp;
  1111.             txt_ptr=txt;
  1112.  
  1113.             while( *sp2 ) {
  1114.                 txt_ptr+=sprintf(txt_ptr,"%s\n",*sp2 );
  1115.                 sp2++;
  1116.             }
  1117.             sprintf(buffer,"%s",def );
  1118.             rtGetStringA(buffer, 63, "Input", NULL, gtag);
  1119.             free( txt );
  1120.             return (string)buffer;
  1121.         }
  1122.     }
  1123.  
  1124.  
  1125.     ys=PrintBox(sp, &x, &y, &w);
  1126.     s = (string) malloc(w+1);
  1127.     s[w] = 0;
  1128.     strncpy(s, def, w);
  1129.     textcolor(2);
  1130.     textbackground(3);
  1131.     gotoxy(1, 25);
  1132.     cputs("Enter text, and when you are finished, press <RETURN>.");
  1133.     textcolor(1);
  1134.     textbackground(0);
  1135.     window(x, y, x+w-1, y);
  1136.     gotoxy(1, ys-1);
  1137.     cprintf("%-*s", w, s);
  1138.     gotoxy(1, ys-1);
  1139.     x = strlen(s);
  1140.     do {
  1141.         if (!(ch = getch()))
  1142.             ch = -getch();
  1143.         if (ch==8 || ch==127)
  1144.             if (!i)
  1145.                 Beep();
  1146.             else {
  1147.                 x = --i;
  1148.                 gotoxy(1+x, ys-1);
  1149.                 cputchar(" ",0);
  1150.                 gotoxy(1+x, ys-1);
  1151.         //        clreol( x );
  1152.             }
  1153.  
  1154. /*        else if (ch==-75)            // left
  1155.             if (!i)
  1156.                 Beep();
  1157.             else {
  1158.                 cputchar("\b",0);
  1159.                 i--;
  1160.             }
  1161.         else if (ch==-77)            // right
  1162.             if (i==x)
  1163.                 Beep();
  1164.             else {
  1165.                 cputchar("%c", s[i]);
  1166.                 i++;
  1167.             }
  1168. */
  1169.         else if (ch!=13 && ch!=27)
  1170.             if (i==w-1)
  1171.                 Beep();
  1172.             else {
  1173.                 cputchar("%c", ch);
  1174.                 if (i==x)
  1175.                     x++;
  1176.                 s[i++] = ch;
  1177.             }
  1178.     } while (ch!=13 && ch!=27);
  1179.     s[x] = 0;
  1180.     if (ch==27) {
  1181.         free(s);
  1182.         strcpy(s = (string) malloc(strlen(def)+1), def);
  1183.     }
  1184.     ClearWin();
  1185.     return s;
  1186.  
  1187. }
  1188.  
  1189.